import { strategyList } from '@/indexDB/initStrategy'
import { ref } from "vue"
import { assetsDB } from '@/indexDB'
import type { HoldItem } from '@/indexDB/initHold'

export const useInnerHold = () => {
  const innerHoldList = ref<HoldItem[]>([])
  const getInnerHoldList = () => {
    assetsDB.holdList.where('type').noneOf(['fund-out', 'currency']).filter(each => !!each.holdNum).toArray()
      .then(arr => {
        innerHoldList.value = arr.map(each => {
          const strategy = strategyList.value.find(item => item.id === each.strategyId)
          return {
            ...each,
            strategyName: strategy?.name
          }
        })
      })
  }

  getInnerHoldList()
  return {
    innerHoldList,
    getInnerHoldList
  }
}